import { robotGetRobotList,robotDelRobot,setThreadLocal,sysUpdateUser,updateRobot,getRobotByName,getcoopRotbotMenus,shareList } from '@/services/overviewRobots';

export default {
  namespace: 'home',

  state: {
   
  },
  effects: {
    *robotGetRobotList({ payload, callback }, { call, put }) { // 根据用户名获取robotlist
      const response = yield call(robotGetRobotList, payload);
      if (response) {
        if (callback && typeof callback === 'function') {
          callback(response);
        }
        yield put({
          type: 'save',
          payload: response,
        });
      }
    },
    *robotDelRobot({ payload, callback }, { call, put }) { // 根据用户名获取robotlist
      const response = yield call(robotDelRobot, payload);
      if (response) {
        if (callback && typeof callback === 'function') {
          callback(response);
        }
        yield put({
          type: 'save',
          payload: response,
        });
      }
    },
    *setThreadLocal({ payload, callback }, { call, put }) { 
      const response = yield call(setThreadLocal, payload);
      if (response) {
        if (callback && typeof callback === 'function') {
          callback(response);
        }
        yield put({
          type: 'save',
          payload: response,
        });
      }
    },
    *sysUpdateUser({ payload, callback }, { call, put }) { 
      const response = yield call(sysUpdateUser, payload);
      if (response) {
        if (callback && typeof callback === 'function') {
          callback(response);
        }
        yield put({
          type: 'save',
          payload: response,
        });
      }
    },
    *updateRobot({ payload, callback }, { call, put }) { 
      const response = yield call(updateRobot, payload);
      if (response) {
        if (callback && typeof callback === 'function') {
          callback(response);
        }
        yield put({
          type: 'save',
          payload: response,
        });
      }
    },
    *getRobotByName({ payload, callback }, { call, put }) { 
      const response = yield call(getRobotByName, payload);
      if (response) {
        if (callback && typeof callback === 'function') {
          callback(response);
        }
        yield put({
          type: 'save',
          payload: response,
        });
      }
    },
    *getcoopRotbotMenus({ payload, callback }, { call, put }) { 
      const response = yield call(getcoopRotbotMenus, payload);
      if (response) {
        if (callback && typeof callback === 'function') {
          callback(response);
        }
        yield put({
          type: 'save',
          payload: response,
        });
      }
    },
    *shareList({ payload, callback }, { call, put }) { 
      const response = yield call(shareList, payload);
      if (response) {
        if (callback && typeof callback === 'function') {
          callback(response);
        }
        yield put({
          type: 'save',
          payload: response,
        });
      }
    },
  },

  reducers: {
    save(state, { payload }) {
      return {
        ...state,
        ...payload,
      };
    },
    fetchb(state,{payload}){
      return {
        ...state,
        ...payload,
      };
    },
    clear() {
      return {
        total:'',
        list:[]
      };
    },
  },
};
